﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BLL.Users;
using BLL.Users.Impl;
using Utils;

public partial class Page_Register_RegisterOfExpert : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }


    //Previous
    protected void btnRegisterExpertPrevious_Click(object sender, ImageClickEventArgs e)
    {
        Response.Write("<script language=javascript>history.go(-2);</script>");
    }


    //注册
    protected void btnRegisterExpertNext_Click(object sender, ImageClickEventArgs e)
    {
        string userName = txtRegisterExpertUserName.Text.Trim();
        string userPassword = txtRegisterExpertPassword.Text.Trim();
        string email = txtRegisterExpertEmail.Text.Trim();
        string securityQuestion = txtRegisterExpertSecurityQuestion.Text.Trim();
        string securityAnswer = txtRegisterExpertSecurityAnswer.Text.Trim();
        string firstName = txtRegisterExpertFirstName.Text.Trim();
        string lastName = txtRegisterExpertLastName.Text.Trim();
        string phone = txtRegisterExpertPhone.Text.Trim();
        string address = txtRegisterExpertAddress.Text.Trim();
        string city = txtRegisterExpertCity.Text.Trim();
        string state = listRegisterExpertState_Province.Text.Trim();
        string postCode = txtRegisterExpertPostalCode.Text.Trim();
        string expertType = listRegisterExpertExpertType.Text.Trim();
        string introduce = txtRegisterExpertIntroduce.Text.Trim();
        User user = new User() 
        {
            UserId=userName,
            UserPassword=userPassword,
            UserType="Expert",
            SecurityQuestion=securityQuestion,
            SecurityAnswer=securityAnswer,
            Visible=1
        };
        Expert expert=new Expert()
        {
            ExpertId=userName,
            ExpertFirstName=firstName,
            ExpertLastName=lastName,
            ExpertPhone=phone,
            ExpertAddress=address,
            ExpertCity=city,
            ExpertEmail=email,
            ExpertState=state,
            ExpertPostalCode=postCode,
            ExpertType=expertType,
            ExpertIntroduce=introduce
        };
        UserManageBO userManageBO = new UserManageBOImpl();
        string resultStr = userManageBO.Register(user,expert);

        if (resultStr.Equals("Register succeed"))
        {
            Response.Write(WebUtil.GetTipsAndRedirect(resultStr, Request.Url, "Home.aspx"));
        }
        else
        {
            Response.Write(WebUtil.GetTipsAndRedirect(resultStr, Request.Url, "Register/RegisterOfExpert.aspx"));
        }
       
    }
}